//
//  RYCRetryPolicy.m
//  EWallet
//
//  Created by mazw on 13-8-23.
//  Copyright (c) 2013年 payegis. All rights reserved.
//

#import "RYCRetryPolicy.h"

NSUInteger RYCRetryPolicyDefaultRetryCount = 2;

@implementation RYCRetryPolicy

+ (id)retryPolicy:(RYCDidStartRetryBlock)startBlock maxRetryCount:(NSUInteger)maxRetryCount
{
    RYCRetryPolicy* policy = [[self alloc] init];
    policy.didStartRetryBlock = startBlock;
    policy.maxRetryCount = maxRetryCount;
    
    return [policy autorelease];
}

- (id)init
{
    self = [super init];
    if (self)
    {
        _maxRetryCount = RYCRetryPolicyDefaultRetryCount;
    }
    return self;
}

- (BOOL)doRetry
{
    if (_retryCount >= _maxRetryCount)
    {
        self.didStartRetryBlock = nil;
        return NO;
    }
    
    if (_didStartRetryBlock)
    {
        _retryCount++;
        _didStartRetryBlock();
        return YES;
    }
    return NO;
}

@end
